<?php

use think\migration\Migrator;
use think\migration\db\Column;

class StoreOrder2 extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        //创建商铺订单(order)表
        $this->table("store_order", ['comment' => '门店-订单表'])
             ->addColumn('no', 'string', ['limit' => 100, 'after' => 'id', 'comment' => '订单编号'])
             ->addColumn('store_user_id', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'no', 'comment' => '用户id'])
             ->addColumn('pay_type', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'store_user_id', 'comment' => '支付类型 1:支付宝,2:微信,3:账期,4:余额,5:大额转账,6:银行卡支付,7:线下支付,8:其他'])
             ->addColumn('order_status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'pay_type', 'comment' => '状态 1:待支付,2:待发货,3:待收货,4:已完成,5:已取消'])
             ->addColumn('buyer_remark', 'string', ['limit' => 200, 'default' => "", 'after' => 'order_status', 'comment' => '买家备注'])
             ->addColumn('voucher', 'string', ['limit' => 1000, 'after' => 'buyer_remark', 'comment' => '支付凭证(截图地址)'])
             ->addColumn('channel', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'voucher', 'comment' => '渠道 1:oms 2:saas'])
             ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'channel', 'comment' => '状态 1:正常,2:禁用'])
             ->addColumn('remark', 'string', ['limit' => 1000, 'after' => 'status', 'comment' => '备注'])
             ->addColumn('create_time', 'integer', ['limit' => 10, 'after' => 'remark', 'default' => 0, 'comment' => '创建时间'])
             ->addColumn('update_time', 'integer', ['limit' => 10, 'after' => 'create_time', 'default' => 0, 'comment' => '更新时间'])
             ->addColumn('delete_time', 'integer', ['limit' => 10, 'after' => 'update_time', 'default' => 0, 'comment' => '删除时间'])
             ->create();


        //创建商铺订单(order_detail)表
        $this->table("store_order_detail", ['comment' => '门店-订单明细表'])
             ->addColumn('store_user_id', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'id', 'comment' => '用户id'])
             ->addColumn('store_order_id', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'store_user_id', 'comment' => '订单id'])
             ->addColumn('goods_id', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'store_order_id', 'comment' => '产品id'])
             ->addColumn('goods_rule_id', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'goods_id', 'comment' => '产品规格id'])
             ->addColumn('quantity', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'goods_rule_id', 'comment' => '数量'])
             ->addColumn('money', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, 'after' => 'quantity', 'comment' => '单价金额'])
             ->addColumn('amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, 'after' => 'money', 'comment' => '总金额'])
             ->addColumn('purchasing_price', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, 'after' => 'amount', 'comment' => '进价金额'])
             ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'purchasing_price', 'comment' => '状态 1:正常,2:禁用'])
             ->addColumn('create_time', 'integer', ['limit' => 10, 'after' => 'status', 'default' => 0, 'comment' => '创建时间'])
             ->addColumn('update_time', 'integer', ['limit' => 10, 'after' => 'create_time', 'default' => 0, 'comment' => '更新时间'])
             ->addColumn('delete_time', 'integer', ['limit' => 10, 'after' => 'update_time', 'default' => 0, 'comment' => '删除时间'])
             ->create();


        //创建商铺订单日志(store_order_log)表
        $this->table("store_order_log", ['comment' => '门店-订单日志表'])
             ->addColumn('store_order_id', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'id', 'comment' => '门店订单id'])
             ->addColumn('order_status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'company_order_id', 'comment' => '状态 1:待支付,2:待发货,3:待收货,4:已完成,5:已取消'])
             ->addColumn('remark', 'string', ['limit' => 1000, 'after' => 'order_status', 'comment' => '备注'])
             ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'remark', 'comment' => '状态 1:正常,2:禁用'])
             ->addColumn('create_time', 'integer', ['limit' => 10, 'after' => 'status', 'default' => 0, 'comment' => '创建时间'])
             ->addColumn('update_time', 'integer', ['limit' => 10, 'after' => 'create_time', 'default' => 0, 'comment' => '更新时间'])
             ->addColumn('delete_time', 'integer', ['limit' => 10, 'after' => 'update_time', 'default' => 0, 'comment' => '删除时间'])
             ->create();
    }
}
